﻿using System;
using System.Collections.Generic;
using System.Text;
using com.huigo.Framework.ServiceUtils;
using com.loto.Common;

namespace com.huigo.Admin.Web.supplier
{
    public partial class SupList : BasePage
    {
        private int pageIndex
        {
            get
            {
                return com.loto.Common.TypeParse.StrToInt(Request.QueryString["page"], 1);
            }
        }

        private string querySup
        {
            get
            {
                return string.IsNullOrEmpty(Request.QueryString["sup"]) ? string.Empty : com.loto.Common.Utils.SqlEscape(Request.QueryString["sup"]);
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void pageInfo_PageChanged(object sender, EventArgs e)
        {
            if (!IsPostBack)
                BindData();
        }

        protected void BindData()
        {
            supName.Text = querySup;
            List<RequestFuncParams> argList = new List<RequestFuncParams>();
            argList.Add(new RequestFuncParams("supName", querySup));
            argList.Add(new RequestFuncParams("pageSize", pageInfo.PageSize.ToString()));
            argList.Add(new RequestFuncParams("pageIndex", pageIndex.ToString()));
            BaseService baseService = new BaseService();
            ParserXml parser = baseService.RequestEntryService(Dict.ERequestFunc.GET_SUP_LIST, argList);

            if (parser != null && parser.RowsCount > 0)
            {
                pageInfo.RecordCount = Convert.ToInt16(parser["RecordCount", 0]);
                pageInfo.CurrentPageIndex = pageIndex;
                pageInfo.PageURLFormat = GetPagerUrl();
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("<table>");
                sb.AppendLine("<thead>");
                sb.AppendLine("<tr>");
                sb.AppendLine("<th style=\"width: 25%\">");
                sb.AppendLine("供应商名称");
                sb.AppendLine("</th>");
                sb.AppendLine("<th style=\"width: 20%\">");
                sb.AppendLine("类型");
                sb.AppendLine("</th>");
                sb.AppendLine("<th style=\"width: 20%\">");
                sb.AppendLine("状态");
                sb.AppendLine("</th>");
                sb.AppendLine("<th style=\"width: 20%\">");
                sb.AppendLine("标记");
                sb.AppendLine("</th>");
                sb.AppendLine("<th>");
                sb.AppendLine("操作");
                sb.AppendLine("</th>");
                sb.AppendLine("</tr>");
                sb.AppendLine("</thead>");
                sb.AppendLine("<tbody>");

                for (int i = 0; i < parser.RowsCount; i++)
                {
                    sb.AppendLine("<tr>");
                    sb.AppendLine("<td>");
                    sb.AppendLine(parser["SupName", i]);
                    sb.AppendLine("</td>");
                    sb.AppendLine("<td>");
                    sb.AppendLine(com.loto.Common.DictEnum.GetDictValueByKey(Dict.DictSupType, Utils.StrToInt(parser["SupType", i], int.MinValue)));
                    sb.AppendLine("</td>");
                    sb.AppendLine("<td>");
                    sb.AppendLine(com.loto.Common.DictEnum.GetDictValueByKey(Dict.DictIsActive, Utils.StrToInt(parser["SupStatus", i], int.MinValue)));
                    sb.AppendLine("</td>");
                    sb.AppendLine("<td>");
                    sb.AppendLine(parser["SupMark", i]);
                    sb.AppendLine("</td>");
                    sb.AppendLine("<td>");
                    sb.AppendLine("<a href=\"AddSup.aspx?sid=" + parser["SupId", i] + "&keepThis=true&amp;TB_iframe=true&amp;height=500&amp;width=850\" title=\"修改供应商-" + parser["ProductName", i] + "\" class=\"thickbox\">修改</a>");
                    sb.AppendLine("</td>");
                    sb.AppendLine("</tr>");
                }
                sb.AppendLine("</tbody>");
                sb.AppendLine("</table>");
                litSup.Text = sb.ToString();
            }
            else
                litSup.Text = string.Empty;


        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            Response.Redirect("SupList.aspx?sup=" + supName.Text);
        }

        private string GetPagerUrl()
        {
            string url = "SupList.aspx?";
            url += "page={0}";
            if (querySup != string.Empty)
                url += "&sup=" + querySup;
            return url;
        }

    }
}
